WebWork 2 : 结果类型
This page last changed on Dec 13, 2004 by casey.
综述结果类型是一些类, 用于决定活动值执行完毕并返回一个结果后应该执行那些动作. 开发者可以根据应用会环境的需要自由的创建自己的结果类型. 在WebWork 2中, 例如, Servlet和Velocity结果类型已经编写完成用来处理视图绘制.注意: 所有WebWork附带的结果类型都实现了com.opensymphony.xwork.Result接口, 它描述了所有活动执行结果的通用接口, 不管是显示Web页面, 生成电子邮件, 发送JMS消息, 等等. 结果类型定义了类并将它映射为到一个名字以便在活动结果配置中引用. 它为这些类提供了简写的名值对.webwork-default.xml的片断 ... <result-types> <result-type name="dispatcher" class="com.opensymphony.webwork.dispatcher.ServletDispatcherResult" default="true"/> <result-type name="redirect" class="com.opensymphony.webwork.dispatcher.ServletRedirectResult"/> <result-type name="velocity" class="com.opensymphony.webwork.dispatcher.VelocityResult"/> <result-type name="chain" class="com.opensymphony.xwork.ActionChainResult"/> <result-type name="xslt" class="com.opensymphony.webwork.views.xslt.XSLTResult"/> <result-type name="jasper" class="com.opensymphony.webwork.views.jasperreports.JasperReportsResult"/> <result-type name="freemarker" class="com.opensymphony.webwork.views.freemarker.FreemarkerResult"/> <result-type name="httpheader" class="com.opensymphony.webwork.dispatcher.HttpHeaderResult"/> <result-type name="stream" class="com.opensymphony.webwork.dispatcher.StreamResult"/> </result-types> ... xwork.xml的片断 <include file="webwork-default.xml"/> <package name="myPackage" extends="default"> <action name="bar" class="myPackage.barAction"> <!-- default result type is "dispatcher" --> <!-- default result name is "success" --> <result>foo.jsp</result> <result name="error">error.jsp</result> </result> </action> </package> Result TypesWebwork提供了com.opensymphony.xwork.Result接口的几个实现使得基于Web的应用容易与活动相结合. 这些结果类型包括:
结果在xwork.xml中指定并嵌套在<action>中. 如果你只需要指定"location"属性, 可以使用简写形式: <action name="bar" class="myPackage.barAction"> <result name="success" type="dispatcher"> <param name="location">foo.jsp</param> </result> </action> 或简写为 <action name="bar" class="myPackage.barAction"> <result name="success" type="dispatcher">foo.jsp</result> </action> 如果你扩展了webwork-default.xml, 那么缺省结果类型是"dispatcher". 如果你不指定结果名字, 它将被指定为"success". 这意味着你个一进一步简写 <action name="bar" class="myPackage.barAction"> <result>foo.jsp</result> </action> 注意: location元素将作为表达式进行解析. 下面的例子说明了这样做的好处: <result name="success" type="redirect">/displayCart.action?userId=${userId}</result> |
Document generated by Confluence on Dec 14, 2004 16:36 |